'use strict';

const {
	Controller
} = require('uni-cloud-router');
const dbcmd = uniCloud.database().command;

module.exports = class MenuController extends Controller {

	// 授权模块菜单
	async auth() {
		let response = {
			code: 1,
		};
		
		let {
			goods,
			detail,
			skus
		} = this.ctx.data;
		
		uniCloud.logger.log('this.ctx.auth', this.ctx.auth);
		
		let objWhere = { enable: true };
		if (this.ctx.auth.role.indexOf('admin') == -1) {
			objWhere._id = dbcmd.in(this.ctx.auth.permission)
		}
		
		const menuRes = await this.db.collection('opendb-admin-menus').where(objWhere).orderBy("sort", "asc").get();
		
		response.code = 0;
		response.datas = menuRes;
		
		return response;
	}

}
